package com.iseastar.guojiang.newcabinet;

import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;

import com.iseastar.BaseActivity2;
import com.iseastar.guojiang.app.TimerService;
import com.iseastar.guojiang.logic.AppLogic;
import com.iseastar.guojiang.util.PollingUtils;
import com.shouhuobao.station.R;

import droid.frame.utils.android.Log;

import static android.os.PowerManager.SCREEN_DIM_WAKE_LOCK;

/**
 * Created by joker on 2018/5/10.
 * 关闭屏幕保持cpu运行不休眠
 * int flags
 * 各种锁的类型对CPU 、屏幕、键盘的影响：
 * PARTIAL_WAKE_LOCK :保持CPU 运转，屏幕和键盘灯有可能是关闭的。
 * SCREEN_DIM_WAKE_LOCK ：保持CPU 运转，允许保持屏幕显示但有可能是灰的，允许关闭键盘灯
 * SCREEN_BRIGHT_WAKE_LOCK ：保持CPU 运转，允许保持屏幕高亮显示，允许关闭键盘灯
 * FULL_WAKE_LOCK ：保持CPU 运转，保持屏幕高亮显示，键盘灯也保持亮度
 */
public class KeepScreenOnActivity extends BaseActivity2 {

    public static KeepScreenOnActivity instance = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d("33333", "启动KeepScreenOnActivity类");
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
                | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
                | SCREEN_DIM_WAKE_LOCK
                | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
                | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
    }

    @Override
    protected void findViewById() {
        setContentView(R.layout.activity_keepscreenon);
        super.findViewById();
        instance = this;
        findViewById(R.id.screen_layout).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AppLogic.courierBackToHomeAndRefresh(getApplication());
                PollingUtils.stopPollingService(getContext(), TimerService.class, TimerService.ACTION);
                finish();
            }
        });
    }

    @Override
    public void finish() {
        super.finish();
    }

    @Override
    protected void onDestroy() {
        instance = null;
        Log.d("33333", "销毁KeepScreenOnActivity类");
        super.onDestroy();
    }
}
